home *** CD-ROM | disk | FTP | other *** search
Text File | 1997-11-09 | 2.6 KB | 113 lines | [TEXT/CWIE] |
- /*************************************************************************************
- #
- TShotSprite.cp
-
- This class represents any shots in the game, friendly or enemy.
-
-
- Author: Timothy Carroll
- Apple Developer Technical Support
- timc@apple.com
-
- Modification History:
-
- 1/23/97 TMC Added include for Moofwars.h so that MrC will compile
- 8/15/96 TMC Initial Release
-
- Copyright © 1996, 1997 Apple Computer, Inc., All Rights Reserved
-
- You may incorporate this sample code into your applications without
- restriction, though the sample code has been provided "AS IS" and the
- responsibility for its operation is 100% yours. However, what you are
- not permitted to do is to redistribute the source as "DSC Sample Code"
- after having made changes. If you're going to re-distribute the source,
- we require that you make it clear in the source that the code was
- descended from Apple Sample Code, but that you've made changes.
-
- *************************************************************************************/
-
- #include "Moofwars.h"
- #include "TShotSprite.h"
-
-
- TShotSprite::TShotSprite (TShotSpriteData *data):
- TSprite((TSpriteData *) data)
- {
- fDuration = data->duration;
- gShotsOnBoard +=1;
- }
-
-
- TShotSprite::~TShotSprite (void)
- {
- gShotsOnBoard -=1;
- }
-
- void
- TShotSprite::ProcessSprite (void)
- {
- // Because of changes in the current implementation, the following code won't compile.
- // It implements a primitive seeking algorithm.
- //
- // We basically look 3 frames ahead and try to move our sprite so that we'll hit the ship.
-
- #if 0
- long deltaX, deltaY;
- deltaX = (gEnemyShipToSeek->fCurrentX+3*gEnemyShipToSeek->fCurVelocityX+(12<<16)
- - this->fCurrentX-3*this->fCurVelocityX);
- deltaY = (gEnemyShipToSeek->fCurrentY+3*gEnemyShipToSeek->fCurVelocityY+(12<<16)
- - this->fCurrentY-3*this->fCurVelocityY);
-
- if (deltaX < 0)
- {
- fCurVelocityX -= (2 << 15);
- }
- else if (deltaX > 0)
- {
- fCurVelocityX += (2 << 15);
- }
-
- if (deltaY < 0)
- {
- fCurVelocityY -= (2 << 15);
- }
- else if (deltaY > 0)
- {
- fCurVelocityY += (2 << 15);
- }
-
- #endif
-
- // If the sprite is invisible, we should delete it, otherwise we should make it invisible
- // if its duration is up.
- #if qShotsHaveRange
- if (fVisibility == kInvisible)
- {
- delete this;
- }
- else
- {
- fDuration -= 1;
- if (fDuration == 0)
- SetVisibility(kInvisible);
- }
- #endif
-
- TSprite::ProcessSprite();
- TSprite::Bounce (&gWorldBounds);
- }
-
- void
- TShotSprite::Collision (TSprite *theSprite)
- {
- #pragma unused (theSprite)
-
- // Change our sprite to the "hit" shape.
- fFace = 2;
-
- if (fDuration > 3)
- fDuration = 3;
- // This will delete the sprite.
- //SetVisibility(kInvisible);
-
- }